package servlets;

import java.io.IOException;

import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import delegate.BusinessDelegate;
import entities.ConfiguracionLog;

/**
 * Servlet implementation class ConfiguracionPortal
 */
@WebServlet("/ConfiguracionPortal")
public class ConfiguracionPortal extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ConfiguracionPortal() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession();
		ConfiguracionLog old = (ConfiguracionLog)session.getAttribute("tipoServicio");
		String login = (String)session.getAttribute("login");
		//llamar al metodo de setear config
		
		String nroGrupo = (String) request.getParameter("nroGrupo");
		String ip = (String) request.getParameter("ip");
		String puerto = (String) request.getParameter("puerto");
		String logDestinoURL = (String) request.getParameter("logDestinoURL");
		String serviceLog = (String) request.getParameter("serviceLog");
		
		Integer nroGr = Integer.parseInt(nroGrupo);
		
		try {
			BusinessDelegate.getInstancia().establecerConfiguracionLog(nroGr, logDestinoURL, serviceLog, ip, puerto);
			old.setConfiguracion(serviceLog);
			old.setIdGrupo(nroGr);
			old.setUrlDestino(logDestinoURL);
			old.setIp(ip);
			old.setPuerto(puerto);
			session.setAttribute("tipoServicio", old);
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		RequestDispatcher dispatcher = request.getRequestDispatcher("/ListarArticulos?operacion=listado");
		dispatcher.forward(request, response);

	}

}
